import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { userInfoApi } from '../services'
import type { userInfo } from '../services/type'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'


export const userStore = defineStore('user', () => {

  const userInfo = ref<userInfo | null>(null)
  const router = useRouter()


  const getUserInfo = async () => {
    try {
      const res = await userInfoApi()
      // console.log(res.data)
      userInfo.value = res.data.values
    } catch(e) {
      // console.log(e)
      if(e.status !== 401) {
        ElMessage.error(e.message)
      }
    }

  }








  return {
    userInfo,
    getUserInfo
   }
})
